package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeTypePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeTypeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.model.dto.response.ServeTypeResDTO;
import com.jzo2o.foundations.service.ServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author Yzxxn
 */
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Autowired
    private ServeService serveService;


    @PutMapping("/offHot/{id}")
    @ApiOperation("区域服务关闭热门状态")
    public void offHot(@PathVariable("id")Long id){
        serveService.offHot(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation("区域服务开启热门状态")
    public void onHot(@PathVariable("id")Long id){
        serveService.onHot(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除区域服务")
    public void deleteServe(@PathVariable("id")Long id){
        serveService.deleteServe(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架")
    public void offSale(@PathVariable("id")Long id){
        serveService.offSale(id);
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    public void onSale(@PathVariable("id")Long id){
        serveService.onSale(id);
    }

    @GetMapping("/page")
    @ApiOperation("区域服务列表分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        return serveService.page(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation("区域服务新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTO) {
        serveService.add(serveUpsertReqDTO);
    }

    @PutMapping("/{id}")
    @ApiOperation("区域服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class)
    })
    public void update(@NotNull(message = "id不能为空") @PathVariable Long id,
                       @RequestParam("price")BigDecimal price){
        serveService.update(id,price);
    }
}
